@extends('_layouts.default')
@section('content')
<!-- this page specific styles -->
<link rel="stylesheet" href="{{ URL::asset('/') }}css/compiled/tables.css" type="text/css" media="screen" />
<div id="pad-wrapper">
    <!-- products table-->
    <!-- the script for the toggle all checkboxes from header is located in js/theme.js -->
    <div class="table-wrapper products-table section">
        <div class="row-fluid head">
            <div class="span12">
                <h4>资讯列表</h4>
            </div>
        </div>

        <div class="row-fluid filter-block">
            <form method="get" action={{ URL('admin/list/') }}>
            <a class="btn-flat" href="{{ URL('admin/info/') }}">Add</a>
            <div class="pull-right">
                <div class="ui-select">
                    <select name="searchData[firstColumnId]" id="first_web_columns">
                        <option value="0">请选择</option>
                        @foreach ($firstWebColumns as $firstWebColumn)
                        <option value="{{$firstWebColumn->id }}" @if($infoSearch->firstColumnId == $firstWebColumn->id) selected="selected" @endif>{{$firstWebColumn->column_name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="ui-select">
                    <select name="searchData[secondColumnId]" id="second_web_columns">
                        <option value="0">请选择</option>
                        @foreach ($secondWebColumns as $secondWebColumn)
                        <option value="{{$secondWebColumn->id }}" @if($infoSearch->secondColumnId == $secondWebColumn->id) selected="selected" @endif>{{$secondWebColumn->column_name}}</option>
                        @endforeach
                    </select>
                </div>
                <input name="searchData[title]" type="text" class="search" value="{{$infoSearch->title}}" />
                <button type="commit" class="btn-flat" value="Search">Search</button>
            </div>
            </form>
        </div>

        <div class="row-fluid">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th class="">
                        资讯标题
                    </th>
                    <th class="">
                        <span class="line"></span>所属类别
                    </th>
                    <th class="span3">
                        <span class="line"></span>发布日期
                    </th>
                </tr>
                </thead>
                <tbody>
                @foreach ($infos as $info)
                <!-- row -->
                <tr class="first">
                    <td>
                        <div class="img">
                            <img src="{{$info->main_img or 'img/table-img.png'}}" />
                        </div>
                        <a href={{ URL('admin/content/'.$info->id) }} class="name">{{$info->title or ''}} </a>
                    </td>
                    <td class="description">
                        {{$info->webColumn->column_name or ''}}
                    </td>
                    <td class="description">
                        {{$info->update_time or ''}}
                        <ul class="actions">
                            <li><a href="{{ URL::asset('/') }}admin/info/{{$info->id}}"><i class="table-edit"></i></a></li>
                            <li class="last"><a href="{{ URL::asset('/') }}admin/delete/{{$info->id}}"><i class="table-delete"></i></a></li>
                        </ul>
                    </td>
                </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    <!-- end products table -->
</div>
{!! $infos->links() !!}
<script>
    $("#first_web_columns").change(function(){
        var parentId = this.value;
        $.ajax({
            url:'/admin/column/get/'+parentId,// 跳转到 action
            type:'get',
            dataType:'json',
            success:function(result) {
                var strSelectOptionHtml = '<option value="-1">请选择</option>';
                if(result['code'] == 0 ){
                    for(var i in result['data']){
                        strSelectOptionHtml += '<option value="'+result['data'][i]['id']+'">'+result['data'][i]['column_name']+'</option>'
                    }
                }
                $("#second_web_columns").html(strSelectOptionHtml);
            }
        });
    });
</script>
@endsection